package org.lansir.af.model;

import java.util.Calendar;

import android.util.Log;

/**
 * Calendar的HaspMap的Key
 * @author 蓝智宏
 *
 */
public class CalendarKey {
	Calendar cal;
	
	
	
	public CalendarKey(Calendar cal){
		this.cal = Calendar.getInstance();
		this.cal.setTimeInMillis(cal.getTimeInMillis());
	}
	
	public Calendar getCalendar(){
		return this.cal;
	}

	public int getYear() {
		return cal.get(Calendar.YEAR);
	}

	public void setYear(int year) {
		cal.set(Calendar.YEAR, year);
	}
	

	public int getDayOfWeek() {
		return cal.get(Calendar.DAY_OF_WEEK);
	}

	public void setDayOfWeek(int dayOfWeek) {
		cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
	}

	public int getMonth() {
		return cal.get(Calendar.MONTH);
	}

	public void setMonth(int month) {
		cal.set(Calendar.MONTH, month);
	}

	public int getDay() {
		return cal.get(Calendar.DAY_OF_MONTH);
	}
	
	public int getDayOfYear(){
		return cal.get(Calendar.DAY_OF_YEAR);
	}

	public void setDay(int day) {
		cal.set(Calendar.DAY_OF_YEAR, day);
	}
	
	public void addDay(){
		cal.add(Calendar.DAY_OF_YEAR, 1);
	}
	
	public int getWeekOfYear(){
		return cal.get(Calendar.WEEK_OF_YEAR);
	}
	
	public boolean IsInOneWeek(Calendar cal){
		Log.v("ActivityFairy", "iWeekOfYear:" + getWeekOfYear() + ", Day:" + getDay());
		Log.v("ActivityFairy", "iWeekOfYear:" + cal.get(Calendar.WEEK_OF_YEAR) + ", Day:" + cal.get(Calendar.DAY_OF_MONTH));
		if((getWeekOfYear() == cal.get(Calendar.WEEK_OF_YEAR)) && getDay() <= cal.get(Calendar.DAY_OF_MONTH))
			return true;
		else if( getWeekOfYear() == (cal.get(Calendar.WEEK_OF_YEAR)+1))
			return true;
		return false;
	}

	@Override
	public int hashCode() {
		return getYear() * 366 + getMonth() * 31 + getDay();
	}

	@Override
	public boolean equals(Object o) {
		return hashCode() == o.hashCode();
	}
	
	
}
